import os
import sys
import string

import django
from django.core.servers.basehttp import AdminMediaHandler
from django.core.handlers.wsgi import *

from container.mwheader import *
from container.mwredirect import *
from container.mwenvironment import *

os.environ['DJANGO_SETTINGS_MODULE'] = 'demo.settings'
current_path = os.path.join(os.getcwd())
if not current_path in sys.path:
    sys.path.append(current_path)

from django.conf import settings

environ = WSGIEnvironment()
environ.seturi(nav_uri.value)
environ.setcookie(cookie.value)
environ.setpost(containerpost.value)
containerpost.value = ''

print "Cookie[%s]" % cookie.value

admin_media_path = django.__path__[0] + '/contrib/admin/media'
application = AdminMediaHandler(WSGIHandler(), admin_media_path)
application = AdminMediaHandler(application, settings.MEDIA_ROOT)
application.media_url = settings.MEDIA_URL
res = application(environ.dict, startcontainer)

cookie.value = getresponsecookie(cookie.value, res)
redirecturi.value = autoredirection(res)
render.value = string.join(res)
